package fi.foyt.cs.controller;

import java.util.List;

import fi.foyt.cs.persistence.dao.task.GeneralTaskLevelCategoryDAO;
import fi.foyt.cs.persistence.dao.task.GeneralTaskDAO;
import fi.foyt.cs.persistence.dao.task.GeneralTaskLevelDAO;
import fi.foyt.cs.persistence.dao.task.TaskRequirementItemDAO;
import fi.foyt.cs.persistence.dao.task.TaskRequirementsDAO;
import fi.foyt.cs.persistence.dao.task.TaskRewardItemDAO;
import fi.foyt.cs.persistence.dao.task.TaskRewardsDAO;
import fi.foyt.cs.persistence.domainmodel.items.Item;
import fi.foyt.cs.persistence.domainmodel.locale.LocaleElement;
import fi.foyt.cs.persistence.domainmodel.scene.SceneCategory;
import fi.foyt.cs.persistence.domainmodel.task.GeneralTask;
import fi.foyt.cs.persistence.domainmodel.task.GeneralTaskLevelCategory;
import fi.foyt.cs.persistence.domainmodel.task.GeneralTaskLevel;
import fi.foyt.cs.persistence.domainmodel.task.TaskRequirementItem;
import fi.foyt.cs.persistence.domainmodel.task.TaskRequirements;
import fi.foyt.cs.persistence.domainmodel.task.TaskRewardItem;
import fi.foyt.cs.persistence.domainmodel.task.TaskRewards;
import fi.foyt.cs.persistence.domainmodel.task.TaskType;

public class TaskController {

  public GeneralTask createGenaralTask(TaskType taskType, LocaleElement localeElement, String icon) {
    GeneralTaskDAO generalTaskDAO = new GeneralTaskDAO();
    
    GeneralTask generalTask = generalTaskDAO.create(taskType, localeElement.getId().getId(), icon);
  
    return generalTask;
  }
  
  public TaskRewards createTaskRewards(Double money) {
    TaskRewardsDAO taskRewardsDAO = new TaskRewardsDAO();
    return taskRewardsDAO.create(money);
  }
  
  public TaskRequirements createTaskRequirements(Double money) {
    TaskRequirementsDAO taskRequirementsDAO = new TaskRequirementsDAO();
    return taskRequirementsDAO.create(money);
  }
  
  public GeneralTaskLevel createGeneralTaskLevel(GeneralTask generalTask, TaskRewards taskRewards, TaskRequirements taskRequirements, Integer levelNumber) {
    GeneralTaskLevelDAO generalTaskLevelDAO = new GeneralTaskLevelDAO();
    return generalTaskLevelDAO.create(generalTask.getId().getId(), taskRewards.getId().getId(), taskRequirements.getId().getId(), levelNumber);
  }
  
  public GeneralTaskLevelCategory createGeneralTaskLevelCategory(GeneralTaskLevel generalTaskLevel, SceneCategory sceneCategory) {
    GeneralTaskLevelCategoryDAO generalTaskCategoryLevelDAO  = new GeneralTaskLevelCategoryDAO();
    return generalTaskCategoryLevelDAO.create(generalTaskLevel.getId().getId(), sceneCategory);
  }
  
  public TaskRequirementItem createTaskRequirementItem(TaskRequirements taskRequirements, Item item, Integer count) {
    TaskRequirementItemDAO taskRequirementItemDAO = new TaskRequirementItemDAO();
    return taskRequirementItemDAO.create(taskRequirements.getId().getId(), item.getId().getId(), count);
  }
  
  public TaskRewardItem createTaskRewardItem(TaskRewards taskRewards,Item item,  Integer count) {
    TaskRewardItemDAO taskRewardItemDAO = new TaskRewardItemDAO();
    return taskRewardItemDAO.create(taskRewards.getId().getId(), item.getId().getId(), count);
  }
  
  public GeneralTask findGeneralTaskById(Long id) {
    GeneralTaskDAO generalTaskDAO = new GeneralTaskDAO();
    return generalTaskDAO.findById(id);
  }
  
  public GeneralTaskLevel findGeneralTaskLevelById(Long id) {
    GeneralTaskLevelDAO generalTaskLevelDAO = new GeneralTaskLevelDAO();
    return generalTaskLevelDAO.findById(id);
  }
  
  public TaskRewards findTaskRewardsById(Long id) {
    TaskRewardsDAO taskRewardsDAO = new TaskRewardsDAO();
    return taskRewardsDAO.findById(id);
  }
  
  public TaskRequirements findTaskRequirementsById(Long id) {
    TaskRequirementsDAO taskRequirementsDAO = new TaskRequirementsDAO();
    return taskRequirementsDAO.findById(id);
  }
  
  public GeneralTaskLevelCategory findGeneralTaskLevelCategoryByGeneralTaskAndCategory(GeneralTaskLevel generalTaskLevel, SceneCategory sceneCategory) {
    GeneralTaskLevelCategoryDAO generalTaskCategoryLevelDAO  = new GeneralTaskLevelCategoryDAO();
    return generalTaskCategoryLevelDAO.findByGeneralTaskLevelAndCategory(generalTaskLevel, sceneCategory);
  }
  
  public TaskRequirementItem findTaskRequirementItemById(Long id) {
    TaskRequirementItemDAO taskRequirementItemDAO = new TaskRequirementItemDAO();
    return taskRequirementItemDAO.findById(id);
  }
  
  public TaskRewardItem findTaskRewardItemById(Long id) {
    TaskRewardItemDAO taskRewardItemDAO = new TaskRewardItemDAO();
    return taskRewardItemDAO.findById(id);
  }
  
  public List<GeneralTask> listGeneralTasks() {
    GeneralTaskDAO generalTaskDAO = new GeneralTaskDAO();
    return generalTaskDAO.listAll();
  }
  
  public List<GeneralTaskLevel> listSceneCategoryGeneralTaskLevels(SceneCategory sceneCategory) {
    GeneralTaskLevelDAO generalTaskLevelDAO = new GeneralTaskLevelDAO();
    return generalTaskLevelDAO.listBySceneCategoryId(sceneCategory.getId().getId());
  }
  
  public List<GeneralTaskLevel> listGeneralTaskLevels(GeneralTask generalTask) {
    GeneralTaskLevelDAO generalTaskLevelDAO = new GeneralTaskLevelDAO();
    return generalTaskLevelDAO.listByGeneralTaskId(generalTask.getId().getId());
  }
  
  public List<TaskRewardItem> listTaskRewardItems(TaskRewards taskRewards) {
    TaskRewardItemDAO taskRewardItemDAO = new TaskRewardItemDAO();
    return taskRewardItemDAO.listByTaskRewardsId(taskRewards.getId().getId());
  }
  
  public List<TaskRequirementItem> listTaskRequirementItems(TaskRequirements taskRequirements) {
    TaskRequirementItemDAO taskRequirementItemDAO = new TaskRequirementItemDAO();
    return taskRequirementItemDAO.listByTaskRequirementsId(taskRequirements.getId().getId());
  }
  
  public GeneralTask updateGeneralTaskType(GeneralTask generalTask, TaskType taskType) {
    GeneralTaskDAO generalTaskDAO = new GeneralTaskDAO();
    return generalTaskDAO.updateTaskType(generalTask, taskType);
  }
  
  public GeneralTask updateGeneralTaskIcon(GeneralTask generalTask, String icon) {
    GeneralTaskDAO generalTaskDAO = new GeneralTaskDAO();
    return generalTaskDAO.updateIcon(generalTask, icon);
  }
  
  public TaskRewards updateTaskRewardsMoney(TaskRewards taskRewards, Double money) {
    TaskRewardsDAO taskRewardsDAO = new TaskRewardsDAO();
    return taskRewardsDAO.updateMoney(taskRewards, money);
  }
  
  public TaskRequirements updateTaskRequirementsMoney(TaskRequirements taskRequirements, Double money) {
    TaskRequirementsDAO taskRequirementsDAO = new TaskRequirementsDAO();
    return taskRequirementsDAO.updateMoney(taskRequirements, money);
  }
  
  public TaskRequirementItem updateTaskRequirementItemCount(TaskRequirementItem taskRequirementItem, Integer count) {
    TaskRequirementItemDAO taskRequirementItemDAO = new TaskRequirementItemDAO();
    return taskRequirementItemDAO.updateCount(taskRequirementItem, count);
  } 
  
  public TaskRequirementItem updateTaskRequirementItemItem(TaskRequirementItem taskRequirementItem, Item item) {
    TaskRequirementItemDAO taskRequirementItemDAO = new TaskRequirementItemDAO();
    return taskRequirementItemDAO.updateItemId(taskRequirementItem, item.getId().getId());
  }  
  
  public TaskRewardItem updateTaskRewardItemCount(TaskRewardItem taskRewardItem, Integer count) {
    TaskRewardItemDAO taskRewardItemDAO = new TaskRewardItemDAO();
    return taskRewardItemDAO.updateCount(taskRewardItem, count);
  }  
  
  public TaskRewardItem updateTaskRewardItemItem(TaskRewardItem taskRewardItem, Item item) {
    TaskRewardItemDAO taskRewardItemDAO = new TaskRewardItemDAO();
    return taskRewardItemDAO.updateItemId(taskRewardItem, item.getId().getId());
  }
  
  public void deleteGeneralTask(GeneralTask generalTask) {
    GeneralTaskDAO generalTaskDAO = new GeneralTaskDAO();
    generalTaskDAO.delete(generalTask);
  }
  
  public void deleteGeneralTaskLevelCategory(GeneralTaskLevelCategory generalTaskLevelCategory) {
    GeneralTaskLevelCategoryDAO generalTaskLevelCategoryDAO = new GeneralTaskLevelCategoryDAO();
    generalTaskLevelCategoryDAO.delete(generalTaskLevelCategory);
  }
  
  public void deleteTaskRequirementItem(TaskRequirementItem taskRequirementItem) {
    TaskRequirementItemDAO taskRequirementItemDAO = new TaskRequirementItemDAO();
    taskRequirementItemDAO.delete(taskRequirementItem);
  }
  
  public void deleteTaskRewardItem(TaskRewardItem taskRewardItem) {
    TaskRewardItemDAO taskRewardItemDAO = new TaskRewardItemDAO();
    taskRewardItemDAO.delete(taskRewardItem);
  }
}
